home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2006 May / PCWMAY06.iso / Software / Freeware / First Page 2006 3.00 / fp2006-final-3.00-setup.exe / {app} / Iscripts / Cookie / display-time-of-last-visit.izs < prev    next >
Text File  |  2005-09-28  |  7KB  |  249 lines

  1. <!NOWIZARD>
  2.  
  3. <!TITLE>Display time of last visit
  4. <!/TITLE>
  5.  
  6. <!DESCRIPTION>This script records the date+time of your visitor's last visit and displays it upon their return. If this is their first visit to your site, a greeting message is shown instead.
  7. <!/DESCRIPTION> 
  8.  
  9. <!CATEGORY>cookies<!/CATEGORY>
  10.  
  11. <!SCRIPT>
  12. <!-- START OF SCRIPT -->
  13. <SCRIPT LANGUAGE = "JavaScript">
  14. <!-- Begin Script
  15.  
  16. var expDays = 30;
  17. var exp = new Date(); 
  18. exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
  19.  
  20. function When(info){
  21.     // When
  22.             var rightNow = new Date()
  23.         var WWHTime = 0;
  24.         WWHTime = GetCookie('WWhenH')
  25.         
  26.         WWHTime = WWHTime * 1
  27.  
  28.         var lastHereFormatting = new Date(WWHTime);  // Date-i-fy that number
  29.             var intLastVisit = (lastHereFormatting.getYear() * 10000)+(lastHereFormatting.getMonth() * 100) + lastHereFormatting.getDate()
  30.             var lastHereInDateFormat = "" + lastHereFormatting;  // Gotta use substring functions
  31.             var dayOfWeek = lastHereInDateFormat.substring(0,3)
  32.             var dateMonth = lastHereInDateFormat.substring(4,10)
  33.         var hours = "" + lastHereFormatting.getHours()
  34.         var year = lastHereFormatting.getYear()
  35.                 if (year < 1000) year+=1900
  36.         var minutes = "" + lastHereFormatting.getMinutes()
  37.         if (minutes.substring(0,1) == minutes){
  38.             minutes = "0" + minutes
  39.         }
  40.             var WWHText = dayOfWeek + ", " + dateMonth + " " + year + " at " +  hours + ":" + minutes// display
  41.     
  42.         SetCookie ("WWhenH", rightNow.getTime(), exp)
  43.  
  44.     return WWHText;
  45. }
  46.  
  47. function Count(info){
  48.     var psj=0;
  49.     // How many times
  50.         var WWHCount = GetCookie('WWHCount')
  51.         if (WWHCount == null) {
  52.             WWHCount = 0;
  53.         }
  54.         else{
  55.             WWHCount++;
  56.         }
  57.         SetCookie ('WWHCount', WWHCount, exp);
  58.  
  59.  
  60.     return WWHCount+1;
  61. }
  62.  
  63.  
  64.  
  65. function set(){
  66. //    VisitorName = prompt("Who are you?", "Nada");
  67. //    SetCookie ('VisitorName', VisitorName, exp);
  68.     SetCookie ('WWHCount', 0, exp);
  69.     SetCookie ('WWhenH', 0, exp);
  70. }
  71.  
  72. function getCookieVal (offset) {  
  73.     var endstr = document.cookie.indexOf (";", offset);  
  74.     if (endstr == -1)    
  75.         endstr = document.cookie.length;  
  76.         return unescape(document.cookie.substring(offset, endstr));
  77. }
  78.  
  79. function GetCookie (name) {  
  80.     var arg = name + "=";  
  81.     var alen = arg.length;  
  82.     var clen = document.cookie.length;  
  83.     var i = 0;  
  84.     while (i < clen) {    
  85.     var j = i + alen;    
  86.     if (document.cookie.substring(i, j) == arg)      
  87.         return getCookieVal (j);    
  88.         i = document.cookie.indexOf(" ", i) + 1;    
  89.         if (i == 0) break;   
  90.     }  
  91.     return null;
  92. }
  93.  
  94. function SetCookie (name, value) {  
  95.     var argv = SetCookie.arguments;  
  96.     var argc = SetCookie.arguments.length;  
  97.     var expires = (argc > 2) ? argv[2] : null;  
  98.     var path = (argc > 3) ? argv[3] : null;  
  99.     var domain = (argc > 4) ? argv[4] : null;  
  100.     var secure = (argc > 5) ? argv[5] : false;  
  101.     document.cookie = name + "=" + escape (value) + 
  102.     ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
  103.     ((path == null) ? "" : ("; path=" + path)) +  
  104.     ((domain == null) ? "" : ("; domain=" + domain)) +    
  105.     ((secure == true) ? "; secure" : "");
  106. }
  107.  
  108. function DeleteCookie (name) {  
  109.     var exp = new Date();  
  110.     exp.setTime (exp.getTime() - 1);  
  111.     // This cookie is history  
  112.     var cval = GetCookie (name);  
  113.     document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
  114.  
  115. }
  116. //  End Script -->
  117. </SCRIPT>
  118. <script>
  119. if (Count()==1){
  120. document.write("This is your 1st visit to our page")
  121. When()
  122. }
  123. else if (Count()>1)
  124. document.write("Welcome back. Your last visit was on <b>" + When() +"</B>.")
  125. </script>
  126. <!-- END OF SCRIPT -->
  127. <!/SCRIPT>
  128.  
  129. <!PREVIEW>
  130. <!-- START OF SCRIPT -->
  131. <SCRIPT LANGUAGE = "JavaScript">
  132. <!-- Begin Script
  133.  
  134. var expDays = 30;
  135. var exp = new Date(); 
  136. exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
  137.  
  138. function When(info){
  139.     // When
  140.             var rightNow = new Date()
  141.         var WWHTime = 0;
  142.         WWHTime = GetCookie('WWhenH')
  143.         
  144.         WWHTime = WWHTime * 1
  145.  
  146.         var lastHereFormatting = new Date(WWHTime);  // Date-i-fy that number
  147.             var intLastVisit = (lastHereFormatting.getYear() * 10000)+(lastHereFormatting.getMonth() * 100) + lastHereFormatting.getDate()
  148.             var lastHereInDateFormat = "" + lastHereFormatting;  // Gotta use substring functions
  149.             var dayOfWeek = lastHereInDateFormat.substring(0,3)
  150.             var dateMonth = lastHereInDateFormat.substring(4,10)
  151.         var hours = "" + lastHereFormatting.getHours()
  152.         var year = lastHereFormatting.getYear()
  153.                 if (year < 1000) year+=1900
  154.         var minutes = "" + lastHereFormatting.getMinutes()
  155.         if (minutes.substring(0,1) == minutes){
  156.             minutes = "0" + minutes
  157.         }
  158.             var WWHText = dayOfWeek + ", " + dateMonth + " " + year + " at " +  hours + ":" + minutes// display
  159.     
  160.         SetCookie ("WWhenH", rightNow.getTime(), exp)
  161.  
  162.     return WWHText;
  163. }
  164.  
  165. function Count(info){
  166.     var psj=0;
  167.     // How many times
  168.         var WWHCount = GetCookie('WWHCount')
  169.         if (WWHCount == null) {
  170.             WWHCount = 0;
  171.         }
  172.         else{
  173.             WWHCount++;
  174.         }
  175.         SetCookie ('WWHCount', WWHCount, exp);
  176.  
  177.  
  178.     return WWHCount+1;
  179. }
  180.  
  181.  
  182.  
  183. function set(){
  184. //    VisitorName = prompt("Who are you?", "Nada");
  185. //    SetCookie ('VisitorName', VisitorName, exp);
  186.     SetCookie ('WWHCount', 0, exp);
  187.     SetCookie ('WWhenH', 0, exp);
  188. }
  189.  
  190. function getCookieVal (offset) {  
  191.     var endstr = document.cookie.indexOf (";", offset);  
  192.     if (endstr == -1)    
  193.         endstr = document.cookie.length;  
  194.         return unescape(document.cookie.substring(offset, endstr));
  195. }
  196.  
  197. function GetCookie (name) {  
  198.     var arg = name + "=";  
  199.     var alen = arg.length;  
  200.     var clen = document.cookie.length;  
  201.     var i = 0;  
  202.     while (i < clen) {    
  203.     var j = i + alen;    
  204.     if (document.cookie.substring(i, j) == arg)      
  205.         return getCookieVal (j);    
  206.         i = document.cookie.indexOf(" ", i) + 1;    
  207.         if (i == 0) break;   
  208.     }  
  209.     return null;
  210. }
  211.  
  212. function SetCookie (name, value) {  
  213.     var argv = SetCookie.arguments;  
  214.     var argc = SetCookie.arguments.length;  
  215.     var expires = (argc > 2) ? argv[2] : null;  
  216.     var path = (argc > 3) ? argv[3] : null;  
  217.     var domain = (argc > 4) ? argv[4] : null;  
  218.     var secure = (argc > 5) ? argv[5] : false;  
  219.     document.cookie = name + "=" + escape (value) + 
  220.     ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
  221.     ((path == null) ? "" : ("; path=" + path)) +  
  222.     ((domain == null) ? "" : ("; domain=" + domain)) +    
  223.     ((secure == true) ? "; secure" : "");
  224. }
  225.  
  226. function DeleteCookie (name) {  
  227.     var exp = new Date();  
  228.     exp.setTime (exp.getTime() - 1);  
  229.     // This cookie is history  
  230.     var cval = GetCookie (name);  
  231.     document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
  232.  
  233. }
  234. //  End Script -->
  235. </SCRIPT>
  236. <script>
  237. if (Count()==1){
  238. document.write("This is your 1st visit to our page")
  239. When()
  240. }
  241. else if (Count()>1)
  242. document.write("Welcome back. Your last visit was on <b>" + When() +"</B>.")
  243. </script>
  244.  
  245. <!-- END OF SCRIPT -->
  246. <!/PREVIEW>
  247.  
  248. <!RELATED>NONE<!/RELATED>
  249.